package com.htw.rv.fast_scroller.slide

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.htw.rv.fast_scroller.R
import com.htw.rv.fast_scroller.adapter.RvItemData
import com.htw.rv.fast_scroller.databinding.LayoutRvLetterItemBinding

const val LETTER_COUNT = 26

class SlideLetterAdapter : RecyclerView.Adapter<SlideLetterAdapterVH>() {

    private val listData = ArrayList<RvItemData>()

    fun initListData() {
        for (index in 0..LETTER_COUNT) {
            val viewType = if (index % 10 == 1) 1 else 0
            val msg = "$index"
            listData.add(
                RvItemData(
                    R.mipmap.ic_launcher,
                    msg,
                    viewType
                )
            )
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SlideLetterAdapterVH {
        return SlideLetterAdapterVH(
            LayoutRvLetterItemBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: SlideLetterAdapterVH, position: Int) {
        holder.bind(listData[position])
    }

    override fun getItemCount(): Int {
        return listData.size
    }

}